home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / mgabra.zip / MGNET.C < prev    next >
Text File  |  1990-02-05  |  39KB  |  1,716 lines

  1. /*****************************************
  2.       NETWORK FUNCTION LIBRARY
  3. *****************************************/
  4.  
  5. /*
  6.  
  7. The following library was built over several years of hacking with the
  8. Novell OS.  Not all the code is guaranteed to exemplify good programming.
  9. (In fact, some of it is darnright embarrassing). The nastiest part of
  10. dealing with the Novell OS is the fact that integers (2 bytes) and
  11. especially troublesome long integers (4 bytes) are swapped in their
  12. byte order. You don't have to worry about that because these functions
  13. handle that. However be careful. I haven't always written everything
  14. clearly enough to show which  swapping return values or parameters
  15. should have.
  16.  
  17. Not all the functions available are here by far. These are just the
  18. ones I found necessary while writing Utilities.
  19.  
  20. I recently rewrote some of the library to use dynamic (on stack) buffers
  21. for the packets. Before I was using statics which consumed data space in
  22. an unnecessarily wasteful manner. I haven't been able to test ALL the
  23. rewritten functions for bugs. If you do have trouble it helps to have the:
  24.  
  25. APPLICATION PROGRAMMER'S GUIDE TO NETWARE AND FUNCTION CALL REFERENCE
  26.  
  27. Which is available from Novell.
  28.  
  29. Walt Howard
  30. 1-31-90
  31. */
  32.  
  33. #include <dos.h>
  34. #include <string.h>
  35. #include <stdio.h>
  36. #include <dir.h>
  37.  
  38. #define WILD 0xFFFF
  39. #define UNKNOWN_TYPE 0
  40. #define NET_USER 1
  41. #define USER_GROUP 2
  42. #define PRINT_SERVER 3
  43. #define FILE_SERVER 4
  44. #define SENDFUNC 0xE1
  45. #define LACKOFSPACE 0xFE
  46. #define DOSSERVICE 0x21
  47. #define MAXBROAD 60
  48. #define LOGFUNC 0xE3
  49. #define DIRFUNC 0xE2
  50. #define TSR 1
  51. #define GETMAP 0x01
  52. #define MAXPATHLENGTH 64
  53. #define GETFILEINFO 0x0f
  54. #define ALLOCATEBASE 0x12
  55.  
  56. #define GETOBJECT 0x16
  57. #define SCANBIND 0x37
  58. #define READPROP 0x3D
  59. #define SEARCH_PATTERN_LENGTH 20
  60. #define BINDERY 0xE3
  61. #define BUZZ 0x00
  62. #define CASTOFF 0x02
  63. #define CASTON 0x03
  64. #define PREF 0xF0
  65. #define FILEINFO 0x0F
  66. #define GETIDNAME 0x36
  67.  
  68. #define MAXSTATIONS 100
  69. #define MAXSEND 60
  70.  
  71. #define WILD 0xFFFF
  72. #define UNKNOWN_TYPE 0
  73. #define NET_USER 1
  74. #define USER_GROUP 2
  75. #define PRINT_SERVER 3
  76. #define FILE_SERVER 4
  77. #define GETOBJECT 0x16
  78. #define SCANBIND 0x37
  79. #define SEARCH_PATTERN_LENGTH 20
  80. #define BINDERY 0xE3
  81. #define MAXSTATIONS 100
  82. #define    COMMFUNC  0xE1
  83. #define OPENPIPE 0x06
  84. #define GETMSG 0x05
  85. #define SENDMSG 0x04
  86. #define PIPESTAT 0x08
  87. #define CLOSEPIPE 0x07
  88. #define MAXMSG 126
  89.  
  90. #define PIPEGOOD 0x00
  91. #define PIPEHALF 0xFE
  92. #define NOSTATION 0xFF
  93.  
  94. typedef int NATIVE;
  95. typedef int WORD;
  96. typedef long LONG;
  97. typedef char BYTE;
  98.  
  99. BYTE spare;
  100. typedef unsigned int REGISTER;
  101.  
  102. union trans {
  103.    char byte[4];
  104.    int intval;
  105.    long longval;
  106. } transform;
  107.  
  108. /*****************************************
  109.                  NETCALL
  110. *****************************************/
  111.  
  112. int netcall(BYTE funcfamily, void far *req, void far *rep)
  113. {
  114.    int rval;
  115.  
  116.    #ifdef TSR
  117.       swapno();
  118.    #endif
  119.    _DI = FP_OFF(rep);
  120.    _SI = FP_OFF(req);
  121.    _ES = FP_SEG(rep);
  122.    _DS = FP_SEG(req);
  123.    _AL = 0;
  124.    _AH = funcfamily;
  125.  
  126.    geninterrupt(0x21);
  127.  
  128.    rval = (int) _AL;
  129.  
  130.    #ifdef TSR
  131.       swapyes();
  132.    #endif
  133.  
  134.    return(rval);
  135.  
  136. }
  137.  
  138. /*****************************************
  139.      BYTE ORDER SWAPPING FUNCTIONS
  140. *****************************************/
  141.  
  142. long swaplong(long longint)
  143. {
  144.  
  145.    transform.longval = longint;
  146.  
  147.    spare = transform.byte[0];
  148.    transform.byte[0] = transform.byte[3];
  149.    transform.byte[3] = spare;
  150.  
  151.    spare = transform.byte[1];
  152.    transform.byte[1] = transform.byte[2];
  153.    transform.byte[2] = spare;
  154.  
  155.    return(transform.longval);
  156.  
  157. }
  158.  
  159. /*****************************************
  160.                 SWAPINT
  161. *****************************************/
  162.  
  163. int swapint(int val)
  164. {
  165.  
  166.    transform.intval = val;
  167.    spare = transform.byte[0];
  168.    transform.byte[0] = transform.byte[1];
  169.    transform.byte[1] = spare;
  170.    return(transform.intval);
  171.  
  172. }
  173.  
  174. #define PROPERTY_SET 0x02
  175. #define GETOBJECTID 0x35
  176. #define ENVIRONMENT 0xF3
  177. #define ADDTRUSTEE 0x0d
  178.  
  179. #define CREATEOBJECT 0x32
  180. #define ADDPROPERTY 0x39
  181. #define MAXOBJECTNAMELENGTH 128
  182. #define MAXPROPERTYNAMELENGTH 128
  183. #define ADDVALUE 0x41
  184. #define MAXMEMBERNAMELENGTH 128
  185. #define ADDITEMVALUE 0x3e
  186. #define SET 0x02
  187. #define ITEM 0x00
  188.  
  189. /* SECURITY DEFINES */
  190.  
  191. #define READ_ANYONE 0xf0
  192. #define READ_ANYONE_LOGGED 0xf1
  193. #define READ_OBJECT_OR_SUPERVISOR 0xf2
  194. #define READ_SUPERVISOR 0xf3
  195. #define READ_BINDERY 0xf4
  196.  
  197. #define WRITE_ANYONE 0x0f
  198. #define WRITE_ANYONE_LOGGED 0x1f
  199. #define WRITE_OBJECT_OR_SUPERVISOR 0x2f
  200. #define WRITE_SUPERVISOR 0x3f
  201. #define WRITE_BINDERY 0x4f
  202.  
  203. /*****************************************
  204.          NOVELL PIPE FUNCTIONS
  205. *****************************************/
  206.  
  207. #define COMMFUNC 0xE1
  208. #define OPENPIPE 0x06
  209. #define GETMSG 0x05
  210. #define SENDMSG 0x04
  211. #define PIPESTAT 0x08
  212. #define CLOSEPIPE 0x07
  213. #define MAXMSG 126
  214. #define PIPEGOOD 0x00
  215. #define PIPEHALF 0xFE
  216. #define NOSTATION 0xFF
  217.  
  218. /*****************************************
  219.              BINDFINDFIRST
  220. *****************************************/
  221.  
  222. static LONG lastobject;
  223.  
  224. int bindfindfirst(WORD patterntype, char *pattern)
  225. {
  226.    int rval;
  227.  
  228.    struct {
  229.       NATIVE packetlength;
  230.       BYTE function;
  231.       LONG lastobjectseen;
  232.       WORD patterntype;
  233.       BYTE patternlength;
  234.       BYTE searchpattern[SEARCH_PATTERN_LENGTH];
  235.    } send;
  236.  
  237.    struct {
  238.       NATIVE packetlength;
  239.       LONG uniqueobjectid;
  240.       WORD objecttype;
  241.       BYTE objectname[48];
  242.       BYTE objectflags;
  243.       BYTE objectsecurity;
  244.       BYTE propertiesexist;
  245.    } recv;
  246.  
  247.    lastobject = -1;
  248.    send.lastobjectseen = swaplong(lastobject);
  249.    lastobject = send.lastobjectseen;
  250.    send.packetlength = sizeof(send) - sizeof(send.packetlength);
  251.    send.function = SCANBIND;
  252.    send.patterntype = swapint(patterntype);
  253.    stpcpy(send.searchpattern, pattern);
  254.    send.patternlength = strlen(send.searchpattern);
  255.    recv.packetlength = sizeof(recv);
  256.    rval = (int) netcall(BINDERY,  &send,  &recv);
  257.    lastobject = recv.uniqueobjectid;
  258.    return(rval);
  259. }
  260.  
  261. /*****************************************
  262.               BINDFINDNEXT
  263. *****************************************/
  264.  
  265. long bindfindnext(void)
  266. {
  267.    int rval;
  268.  
  269.    struct {
  270.       NATIVE packetlength;
  271.       BYTE function;
  272.       LONG lastobjectseen;
  273.       WORD patterntype;
  274.       BYTE patternlength;
  275.       char searchpattern[SEARCH_PATTERN_LENGTH];
  276.    } send;
  277.  
  278.    struct {
  279.       NATIVE packetlength;
  280.       LONG uniqueobjectid;
  281.       WORD objecttype;
  282.       BYTE objectname[48];
  283.       BYTE objectflags;
  284.       BYTE objectsecurity;
  285.       BYTE propertiesexist;
  286.    } recv;
  287.  
  288.    send.packetlength = sizeof(send) - sizeof(send.packetlength);
  289.    send.function = SCANBIND;
  290.    send.lastobjectseen = lastobject;
  291.    recv.packetlength = sizeof(recv);
  292.    rval = netcall(BINDERY,  &send,  &recv);
  293.    lastobject = recv.uniqueobjectid;
  294.    return(rval);
  295.  
  296. }
  297.  
  298. /*****************************************
  299.               GETOBJECTID
  300. *****************************************/
  301.  
  302. long getobjectid(char *name, WORD objecttype)
  303. {
  304.    int rval;
  305.    long temp;
  306.  
  307.    struct {
  308.       NATIVE packetlength;
  309.       BYTE function;
  310.       WORD objecttype;
  311.       BYTE objectnamelength;
  312.       BYTE objectname[MAXOBJECTNAMELENGTH];
  313.    } send;
  314.  
  315.    struct {
  316.       NATIVE packetlength;
  317.       LONG objectid;
  318.       WORD objecttype;
  319.       BYTE objectname[MAXOBJECTNAMELENGTH];
  320.    } recv;
  321.  
  322.    send.function = GETOBJECTID;
  323.    send.objecttype = swapint(objecttype);
  324.    send.objectnamelength = (char) strlen(name);
  325.    strcpy(send.objectname, name);
  326.    send.packetlength = send.objectnamelength + 4;
  327.    recv.packetlength = 54;
  328.    recv.objectid = 0L;
  329.    rval = netcall(BINDERY,  &send,  &recv);
  330.    temp = swaplong(recv.objectid);
  331.    if (rval == 0) return(temp);
  332.    return(0L);
  333.    }
  334.  
  335. /****************************************
  336.              READ PROPERTY
  337. ****************************************/
  338.  
  339. char *getproperty(char *user, char *property)
  340. {
  341.    int rval;
  342.    int temp;
  343.  
  344.    char send[256];
  345.  
  346.    struct {
  347.       NATI